<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>作业2</title>
</head>

<body>
    <script>
        function handleData(arr = [], way = 0) {
            let sum = 0
            for (let i = 0; i < arr.length; i++) {
                sum += arr[i]
            }
            // 参数二为0或不写时求和，为1时求平均数
            if (way === 0) {
                return sum
            } else if (way === 1) {
                return sum / arr.length
            }
        }
        let arr = [3, 5, 2, 6, 5, 1]
        let test = handleData(arr, 0)
        let test1 = handleData(arr, 1)
        console.log(test, test1)
    </script>
</body>

</html>